﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Text;
namespace ZhaoPin.Feature
{
    public partial class GetEduStory : System.Web.UI.Page
    {
        protected StringBuilder sb;
        protected void Page_Load(object sender, EventArgs e)
        {
            Guid guid = (Guid)Membership.GetUser().ProviderUserKey;
            RecruitContainer rc = new RecruitContainer();
            var stories = from st in rc.EduStories where st.PersonId.Equals(guid) orderby st.StartDate ascending select st;
            if (stories.Any())
            {
                List<EduStory> listStories = stories.ToList();
                EduStory start = listStories.ElementAt(0);
                EduStory end = listStories.ElementAt(stories.Count() - 1);
                sb = new StringBuilder();
                sb.Append("第一学历：\r\n");
                writeOneEduStory(start);
                sb.Append("最高学历：\r\n");
                writeOneEduStory(end);
                sb.Append("学习经历：\r\n");
                listStories.ToList<EduStory>().ForEach(es => { writeOneEduStory(es); });
                sb.Remove(sb.Length - 2, 2);
                Response.Write(sb.ToString());
                Response.End();
            }
            else
            {
                Response.Write("");
                Response.End();
            }
            rc.Dispose();
        }
        protected void writeOneEduStory(EduStory es)
        {
            paraStart();
            sb.Append(es.StartDate.Value.ToString("yyyy-MM"));
            appendSpace(2);
            sb.Append(es.EndDate.Value.ToString("yyyy-MM"));
            appendSpace(2);
            sb.Append(es.University);
            appendSpace(2);
            sb.Append(es.Speciality);
            appendSpace(2);
            sb.Append(es.TDictEduLevel.FName);
            appendSpace(2);
            sb.Append(es.TDictDegree.FName);
            appendSpace(2);
            sb.Append(es.TDictEduType.FName);
            appendSpace(2);
            sb.Append(es.TDictEduYear.FName);
            paraEnd();
        }
        protected void appendSpace(int count)
        {
            for (int i = 0; i < count;i++ )
                sb.Append(" ");
        }
        protected void paraStart()
        {
        }
        protected void paraEnd()
        {
            sb.Append("\r\n");
        }
    }
}